﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Windows;
using System.Windows.Interop;
using MapInfo.MiPro.Interop;

namespace CustomMapinfoWindows
{
    public static class Globals
    {
        public static TreeViewItemViewModel TreeSelectedItem { get; set; }

        private static string defualttexteditor;
        public static string DefaultTextEditor
        {
            get
            {
                if (defualttexteditor == null)
                {
                    RegistryKey masterKey = Registry.ClassesRoot.OpenSubKey("txtfile\\shell\\open\\command");
                    string value = masterKey.GetValue(null).ToString();
                    defualttexteditor = value.Replace("%1", "");
                }
                return defualttexteditor;
            }
        }

        public static void Open()
        {
            string shandle = InteropServices.MapInfoApplication.Eval("SystemInfo(9)");
            MainViewWPF window = new MainViewWPF();
            WindowInteropHelper helper = new WindowInteropHelper(window);
            helper.Owner = new IntPtr(Convert.ToInt32(shandle));
            window.Show();
        }
    }

    public class Window : System.Windows.Forms.IWin32Window
    {
        private IntPtr handle;
        public IntPtr Handle
        {
            get { return this.handle; }
            set { this.handle = value; }
        }
    }
 
}
